#include<stdio.h>
#include<string.h>

//i am from nanjing
//gnijnan morf ma i
//nanjing from am i


//逆序算法(首尾互换)
void Reserve(char *s,int len)
{
        for(int i=0;i<len/2;i++)
        {
            char temp=s[i];
            s[i]=s[len-1-i];
            s[len-i-1]=temp;
        }
}
void Reserve2(char *s,int len)
{   
    int count=0;//统计单词长度
    for(int i=0;i<len;i++)
    {   //一个单词结束
        if(s[i]==' '||s[i]=='\0')
        {       //单词逆序
                Reserve(s+i-count,count);
                count=0;
                
        }
        else
        {
            count++;
        }
    }
}

int main()
{
    char str[20]="i am from nanjing";

    Reserve(str,strlen(str));
    Reserve2(str,strlen(str));
    printf("%s\n",str);
     return 0;
}